$(function() {
	$('#newMessageContent').click(function() {
		document.newMessage.newMessageContent.value = "";
	});
	
	$('#newMessageSend').click(function() {
		
		sendMessage();
	});
	
	
	$(document).keypress(function(e) {
	    if(e.which == 13) {
	    	sendMessage();
	    }
	});

	function sendMessage(){
		var message = $("#newMessageContent").val();
		
		if (message == "" || message == "Insira a sua mensagem") {
			return false;
		}
		
		
		var postUrl="http://arguquest.web.ua.pt/clientResources/php/chat/send_message.php";
		
		$.post(postUrl, {'message': message}, function(data){
			//$("#content").html(data);
			$("#newMessageContent").val('');
			$("#messageBox").scrollTop($("#messageBox")[0].scrollHeight);
		});
		
		
		
		
		return false;
	}
});
